package com.xlkj.listener;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

import com.iflytek.cloud.SpeechError;
import com.iflytek.cloud.SynthesizerListener;


public class IflytekSynthesizerListenerImpl implements SynthesizerListener {
    private String TAG = "IflytekSynthesizerListenerImpl";
    //缓冲进度
    private int mPercentForBuffering = 0;
    //播放进度
    private int mPercentForPlaying = 0;

    Activity activity;

    public IflytekSynthesizerListenerImpl(Activity activity){
        this.activity = activity;
    }

    @Override
    public void onSpeakBegin() {
        //Log.d(TAG,"开始播放");
    }

    @Override
    public void onSpeakPaused() {
        //Log.d(TAG,"暂停播放");
    }

    @Override
    public void onSpeakResumed() {
        //Log.d(TAG,"继续播放");
    }

    @Override
    public void onBufferProgress(int percent, int beginPos, int endPos,
                                 String info) {
        // 合成进度
        mPercentForBuffering = percent;
//        Log.d(TAG,String.format(activity.getString(R.string.tts_toast_format),mPercentForBuffering, mPercentForPlaying));
    }

    @Override
    public void onSpeakProgress(int percent, int beginPos, int endPos) {
        // 播放进度
        mPercentForPlaying = percent;
//        Log.d(TAG,String.format(activity.getString(R.string.tts_toast_format),mPercentForBuffering, mPercentForPlaying));

//            SpannableStringBuilder style=new SpannableStringBuilder(texts);
//            Log.e(TAG,"beginPos = "+beginPos +"  endPos = "+endPos);
//            if(!"henry".equals(voicerCloud)||!"xiaoyan".equals(voicerCloud)||
//                    !"xiaoyu".equals(voicerCloud)||!"catherine".equals(voicerCloud))
//                endPos++;
//            style.setSpan(new BackgroundColorSpan(Color.RED),beginPos,endPos, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//            ((EditText) findViewById(R.id.tts_text)).setText(style);
    }

    @Override
    public void onCompleted(SpeechError error) {
        if (error == null) {
//            Log.d(TAG,"播放完成");
        } else if (error != null) {
            Log.d(TAG,error.getPlainDescription(true));
        }
    }

    @Override
    public void onEvent(int eventType, int arg1, int arg2, Bundle obj) {
        // 以下代码用于获取与云端的会话id，当业务出错时将会话id提供给技术支持人员，可用于查询会话日志，定位出错原因
        // 若使用本地能力，会话id为null
        //	if (SpeechEvent.EVENT_SESSION_ID == eventType) {
        //		String sid = obj.getString(SpeechEvent.KEY_EVENT_SESSION_ID);
        //		Log.d(TAG, "session id =" + sid);
        //	}
    }
}
